class A:
    def __enter__(self):
        print("执行了enter")
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        print("执行了exit")

    def __init__(self,num):
        self.num = num

    def show(self):
        print(self.num)

a = A(10)
a.show()
print("*"*100)
#使用with来创建的对象，会自动执行类中的__enter和__exit方法
with A(20) as a1:
    a1.show()